package org.utils.ui.tree;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.io.IOException;

/**
 * Created on 17 juin 2003
 * 
 * @author Manuel EVENO
 */
public class TreeNodeDropListener extends DropTargetAdapter
{
	/**
	 * @see java.awt.dnd.DropTargetListener#dragEnter(java.awt.dnd.DropTargetDragEvent)
	 */
	public void dragEnter(DropTargetDragEvent dtde)
	{
//		Iterator iterator = dtde.getCurrentDataFlavorsAsList().iterator();
//		while (iterator.hasNext())
//		{
//			DataFlavor element = (DataFlavor) iterator.next();
//			System.out.println(element.getHumanPresentableName());
//			System.out.println(element.getMimeType());
//			System.out.println(element.getDefaultRepresentationClass());
//		}
//		dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
	}
	/**
	 * @see java.awt.dnd.DropTargetListener#dragExit(java.awt.dnd.DropTargetEvent)
	 */
	public void dragExit(DropTargetEvent dte)
	{
	}
	/**
	 * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
	 */
	public void drop(DropTargetDropEvent dtde)
	{
		Transferable t = dtde.getTransferable();
//	Iterator iterator = dtde.getCurrentDataFlavorsAsList().iterator();
//	while (iterator.hasNext())
//	{
//		DataFlavor element = (DataFlavor) iterator.next();
//		System.out.println(element.getClass());
//		System.out.println(element.getDefaultRepresentationClassAsString());
//		System.out.println(element.getHumanPresentableName());
//		System.out.println(element.getMimeType());
//		System.out.println(element.getDefaultRepresentationClass());
//	}
		try
		{
			Object s = t.getTransferData( DataFlavor.stringFlavor );
//				new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+"; class=java.io.InputStream")
//			);
			dtde.dropComplete(true);
			System.out.println(s.getClass());
			System.out.println(s);
		}
		catch (UnsupportedFlavorException e)
		{
			dtde.rejectDrop();
			System.err.println(e);
		}
		catch (IOException e)
		{
			dtde.rejectDrop();
			System.err.println(e);
		}
//		catch (ClassNotFoundException e)
//		{
//			dtde.rejectDrop();
//			System.err.println(e);
//		}
	}
}
